
package DAO;

import Entidad.Reporteafiliado;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class ReporteafiliadoDAO {
    
        public boolean save(Reporteafiliado reporte){
        boolean flag = true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans =em.getTransaction();
        try{
            trans.begin();
            em.persist(reporte);
            trans.commit();
        }
        catch(Exception e){
            flag=false;
        }
        return flag;
    }
    public Reporteafiliado getReporteafiliadoById(Integer id){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        return em.find(Reporteafiliado.class, id);
    }
    public boolean update(Reporteafiliado reporte){
        boolean flag =true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans =em.getTransaction();
        try{
            trans.begin();
            em.merge(reporte);
            trans.commit();
        }
        catch(Exception e){
            flag =false;
        }
        return flag;
    }
    public boolean delete(Reporteafiliado reporte){
        boolean flag = true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em =emf.createEntityManager();
        EntityTransaction trans=em.getTransaction();
        try{
            trans.begin();
            em.remove(em.merge(reporte));
            trans.commit();
        }
        catch(Exception e){
            flag=false;
        }
        return flag;
    }
 

}
